package com.eternalrights.controller;

import com.eternalrights.anno.Log;
import com.eternalrights.pojo.Result;
import com.eternalrights.pojo.Student;
import com.eternalrights.pojo.StudentQueryReuslt;
import com.eternalrights.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;

    @GetMapping
    public Result page(StudentQueryReuslt studentQueryReuslt){
        log.info("分页查询学生信息: {}",studentQueryReuslt);
        return Result.success(studentService.page(studentQueryReuslt));
    }

    @PostMapping
    @Log
    public Result saveStudent(@RequestBody Student student){
        log.info("保存学生信息: {}",student);
        studentService.saveStudent(student);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInFo(@PathVariable Integer id){
        log.info("查询指定员工ID: {}",id);
        return Result.success(studentService.getInFo(id));
    }

    @PutMapping
    @Log
    public Result update(@RequestBody Student student){
        log.info("修改员工信息: {}",student);
        studentService.update(student);
        return Result.success();
    }

    @DeleteMapping("/{ids}")
    @Log
    public Result delete(@PathVariable  List<Integer> ids){
        log.info("删除员工:{}",ids);
        studentService.delete(ids);
        return Result.success();
    }

    @PutMapping("/violation/{id}/{score}")
    @Log
    public Result updateViolation(@PathVariable Integer id,@PathVariable Integer score){
        log.info("修改员工:{}",id);
        studentService.updateViolation(id,score);
        return Result.success();
    }
}
